﻿'Params
'limit (Optional) : The number of results to fetch per page. Defaults to 30.
'page (Optional) : The page number to fetch. Defaults to first page.
'tag (Required) : The tag name
'api_key (Required) : A Last.fm API key.
'Auth
'This service does not require authentication. 

Public Structure TagSearchResponse
    Public tags() As Tag
End Structure

Public Class TagSearch

	Inherits BaseRequest
    Dim tag As String = ""
    Dim page As String = ""
    Dim limit As String = ""

	Public xmlresponse As XDocument = Nothing

    Public Sub New(tag As String, page As String, limit As String)
        Me.tag = page
        Me.page = page
        Me.limit = limit
    End Sub

	Public Sub sendRequest()
        InitializeMembers("tag.search")

        AddMember("tag", tag, True)
        AddMember("page", page, False)
        AddMember("limit", limit, False)
        AddMember("api_key", My.Settings.api_key, False)

        xmlresponse = sendPOSTResponse()
	End Sub

    Public Function getResponse() As TagSearchResponse
        Dim response As New TagSearchResponse
        Dim count As New Integer
        Try
            count = xmlresponse.<lfm>.<results>.<tagmatches>.Count()
        Catch ex As Exception
        End Try

        If (count > 0) Then
            For i As Integer = 0 To count - 1
                response.tags(i) = New Tag(xmlresponse.<lfm>.<results>.<tagmatches>(i))
            Next
        End If

        Return response
    End Function
End Class
